package com.example.qiao.mvp.view;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.SPUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.example.qiao.R;
import com.wildma.pictureselector.PictureBean;
import com.wildma.pictureselector.PictureSelector;

import static com.wildma.pictureselector.PictureSelector.PICTURE_RESULT;

public class TouActivity extends AppCompatActivity {

    private TextView tv;
    private ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tou);
        initView();
    }

    private void initView() {
        tv = (TextView) findViewById(R.id.tv);
        iv = (ImageView) findViewById(R.id.iv);
        //图片选择器
        PictureSelector.create(this,100).selectPicture();

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==100&&data!=null){
            PictureBean o = (PictureBean) data.getExtras().get(PICTURE_RESULT);
            SPUtils.getInstance().put("img",o.getPath());
            if (SPUtils.getInstance().getString("img")!=null) {
                Glide.with(this).load(SPUtils.getInstance().getString("img"))
                        .transform(new CircleCrop())
                        .into(iv);
            }
            setResult(RESULT_OK);

        }
    }
}
